<!DOCTYPE html>
<html>
<head>
<meta name="viewport"
	content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<meta charset="UTF-8">
<title>消除过期对象的引用与内存泄漏</title>
<meta name="Keywords" content="消除对象的引用，内存泄漏" />
<meta name="Description" content="" />

</head>
<link type="text/css" rel="stylesheet" href="../styles/main_text.css" />
<body>
	<div class="content">

		<a href="../index.html">目录</a> > <a href="../effective_java.html">高效Java</a>
		<h1>下载gitlab代码，并使用mvn打包</h1>
		<span>请尊重版权！ 如需转载，请联系<a href="#wechat">作者<a />。</span>
		<hr style="margin-bottom: 50px;" />
		<p>此脚本来自公司里的前辈（前辈也是copy自github），自己改了改，用以打包部署maven项目。</p>
		<div class="main_text">
			<div class="code_area">
			<span><span style="color: red">[程序清单01] </span>下载gitlab代码，并使用mvn打包</span>
			<pre class="brush: java">
#!/bin/bash

#step1: git clone http://gitlab.dmall.com/bigdata-search-engine/sqs-client
#step2: 进入目录backup,tmp
#step3: maven编译 mvn clean package
#step4: 启动

REMOTE_REPO="git@gitlab.dmall.com:bigdata-search-engine/sqs-client.git"
PROJECT_NAME="sqs-client"
WORKING_DIR="./tmp"
DEST="./runtime"
BACKUP_DIR="./backups"
SUB_PROJECT_NAME="price-consumer"
WAR_NAME="promotion-consumer-0.0.1-SNAPSHOT"

HELP="Usage: $0 &gt;env&lt;  [command]
    env:        online - deploy to production
                test   - deploy to test
    command:    go - do a real deployment
                &gt;blank&lt; - dry run

Example:
    $0 test go - will deploy test
    $0 online go - will deploy online
"

echo "####################################"
echo "#      DEPLOY SCRIPT               #"
echo "#      FOR 促销价格MQ              #"
echo "####################################"
echo ""

if [ $# = 0 ]; then
    echo "Error: missing parameters!"
fi

if [ $# = 0 ] || [ "$1" = "help" ] || [ "$1" = "h" ]; then
    echo "$HELP"
    exit
fi

if [ "$1" = "online" ]; then
    DIR_SUFFIX=""
    MVN_PROFILE=$1
    echo "Deploying to ONLINE"
elif [ "$1" = "test" ]; then 
    DIR_SUFFIX=""
    MVN_PROFILE=$1
    echo "Deploying to RD"
fi

if [ "$2" = "go" ]; then
    DRY_RUN=0
else
    DRY_RUN=1
    echo "*** This is a DRY RUN ***"
fi

echo ""
echo "+++ Preparing +++"
if [ ! -d "$WORKING_DIR" ]; then
    echo "Create temp folder $WORKING_DIR ..."
    mkdir "$WORKING_DIR"
fi

echo "Go in working directory $WORKING_DIR"
cd "$WORKING_DIR"

need_clone=1

if [ -d "$PROJECT_NAME" ]; then
    if [ -d "$PROJECT_NAME/.git" ]; then
        echo "Local dir exists, try to pull lastest codes ..."
        need_clone=0
        cd "$PROJECT_NAME"
        git pull
    else
        echo "Local dir exists but not under version, delete first ..."
        rm -rf "$PROJECT_NAME"
    fi
fi

if [ "$need_clone" = 1 ]; then
    echo "Clone remote repo $REMOTE_REPO to local"
    git clone -b master "$REMOTE_REPO"
    cd "$PROJECT_NAME"
fi

echo ""
echo "+++ Preparing backup +++"
if [ ! -d "$BACKUP_DIR" ]; then
    echo "Create  folder ../../$BACKUP_DIR ..."
    mkdir "../../$BACKUP_DIR"
fi


echo ""
echo "+++ Backing up +++"
timestamp=`date +"%Y%m%d%H%M"`
echo ""
echo "Backup jar to ${BACKUP_DIR}/${PROJECT_NAME}${DIR_SUFFIX}_${timestamp}.jar ..."
if [ ! "$DRY_RUN" = 1 ]; then
    mv  "./${SUB_PROJECT_NAME}/target/${WAR_NAME}.jar" "../../${BACKUP_DIR}/${SUB_PROJECT_NAME}${DIR_SUFFIX}_${timestamp}.jar"
    echo "Backup end"
fi

#Change to disconf so uncomment
#echo ""
#echo "+++ Checking env config +++"
#if [ ! -f "./${SUB_PROJECT_NAME}/config-test.properties" ]; then
#    if [ ! -f "../../../config-test-search.properties" ]; then
#       echo "Env config does not exists ... "
#       exit
#    fi
#    echo "Init env config to ./${SUB_PROJECT_NAME}/ ..."
#    cp "../../../config-test-search.properties" "./${SUB_PROJECT_NAME}/config-test.properties"
#fi

echo "$WORKING_DIR/$PROJECT_NAME/$SUB_PROJECT_NAME"
echo "current dir is `pwd`"
cd $SUB_PROJECT_NAME
echo ""
echo "+++ Packaging war +++"
echo "current dir is `pwd`"
echo "run maven command  'mvn -U clean package -P$MVN_PROFILE'"
echo ""
/opt/apache-maven-3.3.3/bin/mvn -U clean package -P$MVN_PROFILE

echo "+++ Preparing dest +++"
if [ ! -d "$DEST" ]; then
    echo "Create  folder $DEST ..."
    mkdir -p "$DEST"
fi

echo ""
echo $WAR_NAME
echo "+++ Deploying +++"
echo "Deploy jar"
echo "current dir is $pwd"
if [ ! -f "./${SUB_PROJECT_NAME}/target/${WAR_NAME}" ]; then
  if [ "$DRY_RUN" = 1 ]; then
    rsync --dry-run --force --delete -avPC "./target/${WAR_NAME}.jar" "../../../$DEST/"
  else
    rsync --force --delete -aPC "./target/${WAR_NAME}.jar" "../../../$DEST/"
  fi
fi
echo $pwd
cd ../../../
echo $pwd
echo "==== Done ==="

echo "Change user start ..."
#chown -R dmadmin $DEST

echo "Change group start ..."
#chgrp -R dmadmin $DEST
			</pre>
		</div>
		<hr style="margin-top: 50px;" />
		<p>
			<span style="color: red">反馈、纠错：请通过底部的wechat发送给我，来完善此页面，帮助更多的人学习。</span>
		</p>
		<p><a href="/tks.html">鸣谢</a></p>
		<div style="margin-bottom: 50px;">
				<table>
					<tr>
						<td style="font-weight: 300" height="" width="200px">
							<div
								style="margin-top: 10px;">
								加好友 <img style="margin-top: 5px;" id="wechat" width="170px;" src="../imgs/wechat.png">
								<br />扫描分享到朋友圈
								<p id="qrcode" style="margin-top: 5px;width: 185px; height: 188px; margin: 0;"></p>
								<script type="text/javascript" src="../scripts/qrcode.min.js">
									
								</script>
								<script type="text/javascript" src="../scripts/jquery.min.js"></script>
								<script type="text/javascript">
									var qrcode = new QRCode(document
											.getElementById("qrcode"), {
										width : 170,
										height : 170
									});

									function makeCode() {
										qrcode.makeCode(window.location.href);
									}
									makeCode();
								</script>

							</div>
						</td>
						<td>
							<div
								style="margin-top: 10px; margin-left: 100px; background: rgba(224, 224, 224, 0.22); border: 1px solid rgba(224, 224, 224, 0.22);">
								<div style="margin: 20px;">
									<p style="font-weight: 300">打赏
									<p style="color: blue">如果文中的技术在企业开发中，解决了你的问题，或者避免了你踩坑，请你付费观看，建议30元，但是这不是强制的。针对学生免费。

									
									<div>
										<img width="200px;" src="../imgs/we_pay.png"><img
											width="200px;" src="../imgs/ali_pay.png">

									</div>
								</div>
							</div>
						</td>
					</tr>
					<tr>

					</tr>
				</table>
			</div>
		<!--底部 end  -->
	</div>
</body>

<script type="text/javascript" src="../scripts/XRegExp.js"></script>
<!-- XRegExp is bundled with the final shCore.js during build -->
<script type="text/javascript" src="../scripts/shCore.js"></script>
<script type="text/javascript" src="../scripts/shBrushJScript.js"></script>
<script type="text/javascript" src="../scripts/shBrushJava.js"></script>
<link type="text/css" rel="stylesheet" href="../styles/shCore.css" />
<link type="text/css" rel="Stylesheet"
	href="../styles/shThemeDefault.css" />
<script type="text/javascript">
	//SyntaxHighlighter.all();
</script>

</html>
<script>
	function IsPC() {
		var userAgentInfo = navigator.userAgent;
		var Agents = [ "Android", "iPhone", "SymbianOS", "Windows Phone",
				"iPod" ];
		var flag = true;
		for (var v = 0; v < Agents.length; v++) {
			if (userAgentInfo.indexOf(Agents[v]) > 0) {
				flag = false;
				break;
			}
		}
		if (window.screen.width >= 768) {
			flag = true;
		}
		return flag;
	}
	if (!IsPC()) {
		$(".content").css("width", "100%");
		$("img").css("width", "100%");
		$("pre").css("width", "100%");
		$("pre").css("overflow", "auto");
		/**
		$("pre").css("white-space", "pre-wrap");
		$("pre").css("word-wrap", "break-word");
		 **/

	} else {
		SyntaxHighlighter.all();
	}
</script>